<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/login.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_3414996_dabnbu32yha.css">

</head>

<body>
    <div class="loginwrap">
        <!-- 蒙层 -->
        <div class="logmask">

        </div>
        <div class="login-con">
            <h1 class="logo">SIGN IN</h1>
            <h1 class="title">登录</h1>
            <div class="username inputs">
                <input type="text" name="" id="username" placeholder="请输入用户名">
            </div>
            <div class="pasword inputs">
                <input type="password" name="" id="password" placeholder="请输入密码">
            </div>
            <button id="loginBtn">登录</button>
            <button id="regBtn">
                <a href="#" onclick="toReg()" style="color: #fff;">新用户注册</a>
            </button>
            <div class="wachlog">
                <p>第三方平台登录</p>
                <div class="wacbox">
                    <a href="javascript:;">
                        <i class="iconfont icon-weixin"></i> 微信登录
                    </a>
                </div>
            </div>
        </div>
    </div>

    <script src="../js/axios.min.js"></script>
    <script>

        // 点击注册跳转注册页
        // var regbtn = document.querySelector("#regBtn");
        // regbtn.onclick = function(){
        //     location.href = './register.html';
        // }

        // 点击登录调接口,获取输入框用户名密码
        var loginBtn = document.querySelector("#loginBtn");
        // console.log(loginBtn);
        loginBtn.onclick = function () {
            var username = document.querySelector("#username").value;
            var password = document.querySelector("#password").value;
            // console.log(username,password);
            if (username == '' || password == '') {
                alert("请检查输入是否正确");
                return;
            }
            let loginAPI = 'http://jx.xuzhixiang.top/ap/api/login.php';
            let p = axios.get(loginAPI, { params: { username, password } });
            p.then(r => {
                console.log(r);
                if (r.data.code == 0) {
                    alert(r.data.msg);
                } else {
                    // 登陆成功,跳转首页
                    // 用户名密码存入本地
                    var userArr = r.data.data;
                    // console.log(userArr);
                    localStorage.setItem("usname", userArr.username);
                    localStorage.setItem("uid", userArr.id);
                    alert(r.data.msg + ",跳转首页");
                    location.href = './index.html';

                }
            }) 
        }

        // 点击注册页先跳出iframe 再跳转
        function toReg() {
            window.parent.location.href = '/html/register.html';
        }
    </script>
</body>

</html>